<template>
  <div>
    <el-table :data="guestbookMsg" style="width: 100%">
      <el-table-column prop="username" label="姓名" width="140">
      </el-table-column>
      <el-table-column prop="title" label="标题" width="140"> </el-table-column>
      <el-table-column prop="introduction" label="介绍" width="140">
      </el-table-column>
      <el-table-column label="图片" width="140">
        <template slot-scope="scope">
          <img
            :src="scope.row.picture"
            width="120"
            height="120"
            class="head_pic"
            :preview-src-list="[scope.row.picture]"
          />
        </template>
      </el-table-column>
      <el-table-column prop="content" label="留言"> </el-table-column>
      <el-table-column label="操作" width="140">
        <template slot-scope="scope">
          <el-button
            type="danger"
            icon="el-icon-delete"
            circle
            @click="deleteGuestbook(scope.row.id,scope.row.content)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  name: "guestbook",
  data() {
    return {
      guestbookMsg: [],
    };
  },
  created() {
    this.getGuestbook();
  },
  methods: {
    getGuestbook() {
      let url = "/GuestbookController/getGuestbook";
      let param = "";
      this.$axios
        .get(url, param)
        .then((resp) => {
          this.guestbookMsg = resp.data;
        })
        .catch((err) => {
          console.log("error=", err);
        });
    },
    deleteGuestbook(id,content) {
      let url = "/GuestbookController/deleteGuestbook";
      let guestbook = {
        id: id,
      };
      let param = this.$qs.stringify(guestbook);
      this.$confirm("此操作将永久删除" + content + "留言, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios
            .post(url, param)
            .then((resp) => {
              if (resp.data) {
                this.$message({
                  type: "success",
                  message: "删除成功!",
                });
                this.getGuestbook();
              } else {
                this.$message({
                  type: "error",
                  message: "删除失败!",
                });
              }
            })
            .catch((err) => {
              console.log("error=", err);
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
};
</script>
<style scoped>
</style>